package org.example.servide.lmpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.example.domain.Zero;
import org.example.mapper.ZeroMapper;
import org.example.servide.ZeroService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class ZeroServicelmpl extends ServiceImpl<ZeroMapper,Zero> implements ZeroService{

    @Autowired
    ZeroMapper zeroMapper;

    @Autowired
    RocketMQTemplate rocketMQTemplate;
    @Override
    public Zero getZero(String outTradeNo) {
        return zeroMapper.getZero(outTradeNo);
    }

    @Override
    public List<Zero> lists(String tradeName) {
        return zeroMapper.lists(tradeName);
    }

    @Override
    public void docallback(String outTradeNo, String tradeNo, BigDecimal bigDecimal) {
        Zero zero = zeroMapper.getZero(outTradeNo);
        if (zero != null) {
            zeroMapper.updateZero(zero);
        }

        rocketMQTemplate.asyncSend("toPay420", "支付成功", new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println("发送成功");
            }

            @Override
            public void onException(Throwable throwable) {
                System.out.println("发送失败");
            }
        });
    }

    @Override
    public List<Zero> lookstatus() {
        return zeroMapper.lookstatus();
    }

    @Override
    public void updateZerototal(Zero zero) {
        zeroMapper.updateZerototal(zero);
    }

    @Override
    public Zero getId(Integer id) {
        return zeroMapper.getId(id);
    }

    @Override
    public boolean addZero(Zero zero) {
        return zeroMapper.addZero(zero);
    }


}
